package com.yiquan.user.dao.db;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.yiquan.user.pojo.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface UserDao extends JpaRepository<User,Long>,JpaSpecificationExecutor<User>{

    @Query(nativeQuery = true,value = "select * from  yiquan_user where user_id = ?")
    User findUserByUserId(Long userId);

    User findUserByUsernameAndPassword(String username, String password);

    User findUserByUsername(String username);

    User findUserByPhone(String phone);


    @Query(nativeQuery = true,value = "update yiquan_user set fan_nums = fan_nums + ?2 where user_id = ?1")
    @Modifying
    @Transactional
    void updateFansNum(Long userId,Integer nums);

    @Query(nativeQuery = true,value = "update yiquan_user set follow_nums = follow_nums + ?2 where user_id = ?1")
    @Modifying
    @Transactional
    void updateFollowNum(Long userId,Integer nums);

    @Query(nativeQuery = true,value = "update yiquan_user set works_nums = works_nums + ?2 where user_id = ?1")
    @Modifying
    @Transactional
    void updateWorksNum(Long userId,Integer nums);
}
